﻿using Cookbook.Models;
using Cookbook.Services;
using Microsoft.Practices.Prism.StoreApps;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace Cookbook.ViewModels
{
  public class RecipesViewModel : INotifyPropertyChanged
  {
    private IEnumerable<Recipe> recipes;

    public IEnumerable<Recipe> Recipes
    {
      get { return recipes; }
      set 
      { 
        this.recipes = value; 
        if (PropertyChanged != null)
        {
          PropertyChanged(this, new PropertyChangedEventArgs("Recipes"));
        }
      }
    }

    public RecipesViewModel()
    {
      this.Recipes = new List<Recipe>();
    }

    public async Task LoadRecipes()
    {
      var recipes = await RecipeService.GetRecipes();
      this.Recipes = new List<Recipe>(recipes);
    }

    public event PropertyChangedEventHandler PropertyChanged;
  }
}
